package com.crm.service.impl;

import com.crm.dao.PermissionMapper;
import com.crm.domain.DataGridView;
import com.crm.pojo.Permission;
import com.crm.service.PermissionService;
import com.crm.vo.PermissionVo;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PermissionServiceImpl implements PermissionService {
    @Autowired
    private PermissionMapper permissionMapper;

    @Override
    public List<Permission> selectAllMenus() {
        return permissionMapper.selectAllPermissions();
    }


    @Override
    public List<Permission> selectMenuIdsByRid(int rid) {
        List<Permission> permissionList = permissionMapper.selectPermissionsByRid(rid);
        return permissionList;
    }

    @Override
    public DataGridView findAllPermissions(PermissionVo permissionVo) {
        Page<Object> page = PageHelper.startPage(permissionVo.getPage(), permissionVo.getLimit());
        List<Permission> permissionList = this.permissionMapper.selectAllPermissions();
        return new DataGridView(page.getTotal(), permissionList);
    }


}
